package com.xuecheng.content.model.dto;

import com.xuecheng.content.model.po.CourseCategory;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 课程分类树形节点dto
 */
@Data
@ApiModel(value = "CourseCategoryTreeDto", description = "课程分类树形节点dto")
public class CourseCategoryTreeDto extends CourseCategory implements Serializable {

    @ApiModelProperty(value = "子节点")
    private List<CourseCategoryTreeDto> childrenTreeNodes;

    public static CourseCategoryTreeDto convert(CourseCategory courseCategory) {
        CourseCategoryTreeDto courseCategoryTreeDto = new CourseCategoryTreeDto();
        courseCategoryTreeDto.setId(courseCategory.getId());
        courseCategoryTreeDto.setName(courseCategory.getName());
        courseCategoryTreeDto.setOrderby(courseCategory.getOrderby());
        courseCategoryTreeDto.setLabel(courseCategory.getLabel());
        courseCategoryTreeDto.setParentid(courseCategory.getParentid());
        courseCategoryTreeDto.setIsLeaf(courseCategory.getIsLeaf());
        return courseCategoryTreeDto;
    }

    public void addChild(CourseCategoryTreeDto courseCategoryTreeDto) {
        if (childrenTreeNodes == null) {
            childrenTreeNodes = new ArrayList<>();
        }
        childrenTreeNodes.add(courseCategoryTreeDto);
    }
}
